//
//  LPZWYCommonSpecilTableViewCell.m
//  ZhongWangYuan
//
//  Created by liuyingping on 2018/6/2.
//  Copyright © 2018年 ZJ. All rights reserved.
//

#import "LPZWYCommonSpecilTableViewCell.h"
#define TopGreen @"5bb85d"
#define TopOrange @"ffa016"
@interface LPZWYCommonSpecilTableViewCell ()
/**    */
@property (strong, nonatomic) TenGrayShadowView  *ten;
/**  图片  */
@property (strong, nonatomic) UIImageView  *leftImageView;
/**  专题类型  */
@property (strong, nonatomic) UILabel  *typeLabel;
/**  专题是否结业  */
@property (strong, nonatomic) UILabel  *finishLabel;

/**  title  */
@property (strong, nonatomic) UILabel  *titleLabel;
/**    */
@property (strong, nonatomic) UIView  *bottomSlider;
/**    */
@property (strong, nonatomic)  UIView *topSlider;
/**    */
@property (strong, nonatomic) UILabel  *baifenbi;
/**  必修学时  */
@property (strong, nonatomic) UILabel  *must;
/**  选修学时  */
@property (strong, nonatomic) UILabel  *optional;
/**    */
@property (strong, nonatomic) UILabel  *statusLabel;



@end

// 125
@implementation LPZWYCommonSpecilTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self layoutUI];
    }
    return self;
}


- (void)layoutUI{
    [self addSubview:self.ten];
    [self addSubview:self.leftImageView];
    [self.leftImageView addSubview:self.typeLabel];
    [self.leftImageView addSubview:self.finishLabel];
    [self.leftImageView addSubview:self.statusLabel];
    [self addSubview:self.titleLabel];
    [self addSubview:self.bottomSlider];
    [self.bottomSlider addSubview:self.topSlider];
    [self addSubview:self.baifenbi];
    [self addSubview:self.must];
    [self addSubview:self.optional];
    
    
    self.ten.sd_layout
    .leftEqualToView(self)
    .topEqualToView(self)
    .rightEqualToView(self)
    .heightIs(7 * [UIScreen zj_screenHScale]);
    
    self.leftImageView.sd_layout
    .leftSpaceToView(self, 15 * [UIScreen zj_screenWScale])
    .topSpaceToView(self.ten, 15 * [UIScreen zj_screenHScale])
    .heightIs(85 * [UIScreen zj_screenHScale])
    .widthIs(130 * [UIScreen zj_screenWScale]);
    
    
    self.typeLabel.sd_layout
    .topEqualToView(self.leftImageView)
    .leftEqualToView(self.leftImageView)
    .heightIs(20 * [UIScreen zj_screenHScale])
    .widthIs(45 * [UIScreen zj_screenWScale]);
     [self.typeLabel setRadius:4 byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight];
    
    self.finishLabel.sd_layout
    .topEqualToView(self.leftImageView)
    .rightEqualToView(self.leftImageView)
    .heightIs(20 * [UIScreen zj_screenHScale])
    .widthIs(45 * [UIScreen zj_screenWScale]);
    [self.finishLabel setRadius:4 byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight];
    
    self.statusLabel.sd_layout
    .topEqualToView(self.leftImageView)
    .rightEqualToView(self.leftImageView)
    .heightIs(20 * [UIScreen zj_screenHScale])
    .widthIs(45 * [UIScreen zj_screenWScale]);
    
    
    self.must.sd_layout
    .leftSpaceToView(self.leftImageView, 10 * [UIScreen zj_screenWScale])
    .bottomEqualToView(self.leftImageView)
    .heightIs(10 * [UIScreen zj_screenHScale])
    .widthIs(([UIScreen zj_screenWith] - 175 * [UIScreen zj_screenWScale]) / 2);
    
    self.optional.sd_layout
    .leftSpaceToView(self.must, 10 * [UIScreen zj_screenWScale])
    .bottomEqualToView(self.must)
    .heightIs(10 * [UIScreen zj_screenHScale])
    .widthIs(([UIScreen zj_screenWith] - 175 * [UIScreen zj_screenWScale]) / 2);
    
    
    self.baifenbi.sd_layout
    .rightSpaceToView(self, 10 * [UIScreen zj_screenWScale])
    .heightIs(10 * [UIScreen zj_screenHScale])
    .widthIs(40 * [UIScreen zj_screenWScale])
    .bottomSpaceToView(self.must, 15 * [UIScreen zj_screenHScale]);
    
    self.bottomSlider.sd_layout
    .leftEqualToView(self.must)
    .rightSpaceToView(self.baifenbi, 5 * [UIScreen zj_screenWScale])
    .bottomEqualToView(self.baifenbi)
    .heightIs(10 * [UIScreen zj_screenHScale]);
    
    self.topSlider.sd_layout
    .leftEqualToView(self.bottomSlider)
    .topEqualToView(self.bottomSlider)
    .widthIs(100)
    .heightIs(10 * [UIScreen zj_screenHScale]);
    
    
    self.titleLabel.sd_layout
    .leftEqualToView(self.must)
    .topEqualToView(self.leftImageView)
    .heightIs(40 * [UIScreen zj_screenHScale])
    .widthIs([UIScreen zj_screenWith] - 165 * [UIScreen zj_screenWScale]);
    
    
    /**  计算出每百分之一所占比例  */
    CGFloat bilie =  ([UIScreen zj_screenWith] - 210 * [UIScreen zj_screenWScale]) / 100;
    
    self.topSlider.sd_layout
    .widthIs(bilie * 100);
    [self.topSlider updateLayout];
    
    
    
}

- (void)setModel:(LPZWYChooseClassClassModel *)model{
    _model = model;
    [self.leftImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@" , CREATEURL(model.image_servername)]] placeholderImage:PlaceholderImage];
    
    self.titleLabel.text = [NSString isNilStringReturnString: model.name];
    CGFloat height = [self.titleLabel getLableSizeWithMaxWidth:self.titleLabel.width].height;
    
    if (height > 40 * [UIScreen zj_screenHScale]) {
        self.titleLabel.sd_layout.heightIs(40 * [UIScreen zj_screenHScale]);
        [self.titleLabel updateLayout];
    }else{
        self.titleLabel.sd_layout.heightIs(height);
        [self.titleLabel updateLayout];
    }
    
    self.typeLabel.text = @"专题班";
    
    
    self.must.text = [NSString stringWithFormat:@"必修学时:%.1lf/%.1f",[model.requiredfinishedstudytime floatValue],[model.requiredstudytime floatValue]];
    
    self.optional.text = [NSString stringWithFormat:@"选修学时:%.1lf/%.1f",[model.electivefinishedstudytime floatValue],[model.electivestudytime floatValue]];
    
    
    /**  计算出每百分之一所占比例  */
    CGFloat bilie =  ([UIScreen zj_screenWith] - 210 * [UIScreen zj_screenWScale]) / 100;
    NSString *progress;
    if (model.finishprogress.length != 0) {
        progress = model.finishprogress;
        if ([progress floatValue] > 1) {
            progress = model.schedulecomp;
        }
    }else if (model.progress.length != 0){
        progress = model.progress;
    }else{
        progress = model.playpercentage;
    }
   
    
    NSInteger shuzi = (NSInteger)([progress floatValue] * 100);
    NSString *number = [NSString stringWithFormat:@"%ld",(long)shuzi];
    self.baifenbi.text = [NSString stringWithFormat:@"%@%%",number];
    
    if ([number integerValue] == 0) {
        self.topSlider.hidden = YES;
         self.baifenbi.textColor = [UIColor zj_colorWithHexString:TopOrange];
    }else if ([number integerValue] == 100){
        self.topSlider.hidden = NO;
        self.topSlider.backgroundColor = [UIColor zj_colorWithHexString:TopGreen];
        self.baifenbi.textColor =  [UIColor zj_colorWithHexString:TopGreen];
        self.topSlider.sd_layout
        .widthIs(bilie * 100);
        [self.topSlider updateLayout];
    }else{
        self.topSlider.hidden = NO;
        self.topSlider.backgroundColor = [UIColor zj_colorWithHexString:TopOrange];
        self.baifenbi.textColor = [UIColor zj_colorWithHexString:TopOrange];
        
        self.topSlider.sd_layout
        .widthIs(bilie * [number integerValue]);
        [self.topSlider updateLayout];
    }
    
    
    if (self.isShowEnd) {
        self.statusLabel.hidden = YES;
        if ([model.graduatestatus integerValue] == 1) {
            self.finishLabel.hidden = NO;
            self.finishLabel.text = @"已结业";
        }else{
            self.finishLabel.hidden = YES;
           
        }
    }else{
         self.finishLabel.hidden = YES;
        if ([model.ifsignup integerValue] == 1) {
            self.statusLabel.text = @"已报名";
        }else{
            if ([model.ishows integerValue] == 0) {
                self.statusLabel.text = @"未报名";
            }else{
                if ([model.appmainstatus integerValue] == 0) {
                    self.statusLabel.text = @"报名审核中";
                }else{
                    self.statusLabel.text = @"未报名";
                }
                
            }
        }
        CGFloat width = [CalculateLabelHeight CalculateLabelWidthWithString:self.statusLabel.text font:13 height:20].width;
        self.statusLabel.sd_layout.widthIs(width);
        [self.statusLabel updateLayout];
        [self.statusLabel setRadius:4 byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight];
        
    }
    
    if (YBUSERINFOMODEL.studentId.length == 0) {
        self.bottomSlider.hidden = YES;
        self.baifenbi.hidden = YES;
    }
   
}

#pragma mark - setter

- (TenGrayShadowView *)ten{
    if (_ten == nil) {
        _ten = [TenGrayShadowView new];
        
    }
    return _ten;
}

- (UIImageView *)leftImageView{
    if (_leftImageView == nil) {
        _leftImageView = [UIImageView new];
        _leftImageView.layer.masksToBounds = YES;
        _leftImageView.layer.cornerRadius = 4;
        
    }
    return _leftImageView;
}

- (UILabel *)typeLabel{
    if (_typeLabel == nil) {
        _typeLabel = [UILabel new];
        _typeLabel.backgroundColor = [UIColor themeColor];
        _typeLabel.textColor = [UIColor whiteColor];
        _typeLabel.textAlignment = NSTextAlignmentCenter;
        _typeLabel.font = LYPFONT(13);
        _typeLabel.layer.masksToBounds = YES;
       
    }
    return _typeLabel;
}

- (UILabel *)statusLabel{
    if (_statusLabel == nil) {
        _statusLabel = [UILabel new];
        _statusLabel.backgroundColor = [UIColor themeColor];
        _statusLabel.textColor = [UIColor whiteColor];
        _statusLabel.textAlignment = NSTextAlignmentCenter;
        _statusLabel.font = LYPFONT(13);
        _statusLabel.layer.masksToBounds = YES;
        
    }
    return _statusLabel;
}


- (UILabel *)finishLabel{
    if (_finishLabel == nil) {
        _finishLabel = [UILabel new];
        _finishLabel.backgroundColor = [UIColor zj_colorWithHexString:@"008000"];
        _finishLabel.textColor = [UIColor whiteColor];
        _finishLabel.textAlignment = NSTextAlignmentCenter;
        _finishLabel.font = LYPFONT(13);
        _finishLabel.layer.masksToBounds = YES;
        
    }
    return _finishLabel;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.numberOfLines = 0;
        _titleLabel.font = LYPFONT(15);
        _titleLabel.textColor = [UIColor textGrayColor];
        
    }
    return _titleLabel;
}

- (UIView *)bottomSlider{
    if (!_bottomSlider) {
        _bottomSlider = [UIView new];
        _bottomSlider.backgroundColor = [UIColor themeGrayColor];
        _bottomSlider.layer.masksToBounds = YES;
        _bottomSlider.layer.cornerRadius = 5;
        
    }
    return _bottomSlider;
}


- (UIView *)topSlider{
    if (!_topSlider) {
        _topSlider = [UIView new];
        _topSlider.layer.masksToBounds = YES;
        _topSlider.layer.cornerRadius = 5;
        
    }
    return _topSlider;
}

- (UILabel *)baifenbi{
    if (!_baifenbi) {
        _baifenbi = [UILabel new];
        _baifenbi.textColor = [UIColor zj_colorWithHexString:@"ff7202"];
        _baifenbi.textAlignment = NSTextAlignmentCenter;
        _baifenbi.font = LYPFONT(14);
    }
    return _baifenbi;
}

- (UILabel *)must{
    if (!_must) {
        _must = [UILabel new];
        _must.textColor = [UIColor lightGrayColor];
        _must.font = LYPFONT(12);
        
    }
    return _must;
}

- (UILabel *)optional{
    if (!_optional) {
        _optional = [UILabel new];
        _optional.textColor = [UIColor lightGrayColor];
        _optional.font = LYPFONT(12);
        
    }
    return _optional;
}




@end
